<?php

require_once( '../../libs/smarty.inc' );
require_once( '../../libs/smt_variables.php' );
require_once( '../../libs/Class_DB.php' );
require_once( '../../libs/Class_ERROR.php' );
require_once( '../../libs/login.inc.php' );
require_once( '../../libs/const.php' );
require_once( '../../libs/new_smt_variables.php' );

if( !in_array( "N", $_SESSION['ADMIN_LOGIN']['AUTH_CD'] ) ) exit;

if( $_SERVER['REQUEST_METHOD'] == 'GET' ){
	
	$order_id = $_GET['order_id'];
	$db = new Class_DB;
	
	$db->query("UPDATE k_order_head set sale_status = 1 where order_id ='$order_id'");
	
	$sql = "SELECT * FROM k_order_head WHERE order_id = '$order_id'";
	$result = $db->query($sql);
	$row = mysql_fetch_array($result);
	$row['bookdate']=$row['bookdate']==NULL?"":date('Y年m月d日',strtotime($row['bookdate']));
	$row['delivery_date']=$row['delivery_date']==NULL?"":date('Y/m/d',strtotime($row['delivery_date']));
	$order = $row;
	$smarty->assign('order', $row);
	
	$sql = "SELECT * FROM k_order_detail as a WHERE a.order_id='$order_id'";
	$result = $db->query($sql);
	$row1 = array();
	$m1 = 0;
	$m11 = 0;
	while( $row = mysql_fetch_array($result,MYSQL_ASSOC) ){
		$row['money'] = $row['refer_price']*$row['quantity'];
		$m1 = $m1+$row['money'];
		$m11 = $m11+$row['cost_price']*$row['quantity'];
		$row['money'] = number_format($row['refer_price']*$row['quantity']);
		$row['refer_price'] = number_format(intval($row['refer_price']));
		$row1[] = $row;
	}
	$m2 = $m1 - $m1*$order['discount'];
	$m3 = $order['shipping'];
	$m4 = round(($m1*$order['discount']+$m3)*$order['tax'],0);
	$m5 = $m1-$m2 +$m3+$m4;
	if($m1==0){
		$profit = 0;
	}else{
		$profit = round((($m1*$order['discount']-$m11)/$m1*$order['discount'])*100,2);
	}
	$smarty->assign('m1', number_format($m1));
	$smarty->assign('m2', number_format($m2));
	$smarty->assign('m3', number_format($m3));
	$smarty->assign('m4', number_format($m4));
	$smarty->assign('m5', number_format($m5));
	$smarty->assign('profit', $profit."%");
	$smarty->assign('detail', $row1);
	$smarty->assign('flag', 0);
	$smarty->assign('tax', $tax);
	$smarty->assign('maker', $_SESSION['ADMIN_LOGIN']['STAFF_NAME']);
	$smarty->assign('num', count($row1)+1);
	
	
}


$menu_html = file_get_contents( $_SERVER['DOCUMENT_ROOT'].'/templates/web-admin/menu.html' );
$smarty->assign('menu_html', $menu_html);
$smarty->display('web-admin/order_yes_book.html');


?>